package com.lzhpo.admin.controller;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.lzhpo.admin.controller.base.BaseController;
import com.lzhpo.admin.entity.vo.SelectCondition;
import com.lzhpo.common.config.MySysUser;
import com.lzhpo.core.config.RedisUtil;
import com.lzhpo.core.utils.JsonResp;
import com.lzhpo.core.utils.RedisConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.PostConstruct;
import java.util.Map;

/**
 * <p> Author：lzhpo </p>
 * <p> Title：</p>
 * <p> Description：主要是基本走势</p>
 */
@Controller
@RequestMapping("/index")
public class IndexController extends BaseController {

    private final static Logger LOGGER = LoggerFactory.getLogger(IndexController.class);

    public final static String LOGIN_TYPE = "loginType";


    private static Map<Integer, String> data_user_condition = Maps.newHashMap();


    @Autowired
    private RedisUtil redisUtil;


    @PostConstruct
    public void init() {
        data_user_condition.put(2, RedisConstant.USER_CONDITION);
        data_user_condition.put(3, RedisConstant.USER_CONDITION_FIVE);
    }


    @PostMapping("/setConditionFault")
    @ResponseBody
    public JsonResp dealWithPass(Boolean isFault, String id, Integer type) {
        System.out.println();
        String conditionStr = redisUtil.hget(data_user_condition.get(type) + MySysUser.id(), id);
        SelectCondition condition = JSONObject.parseObject(conditionStr, SelectCondition.class);
        condition.setFault(isFault);
        if (type == 2) {
            saveBeijingBoatDataToRedis(condition);
        }
        if (type == 3) {
            saveRangeFiveDataToRedis(condition);
        }
        return JsonResp.success();
    }

    /**
     * redisUtil.hset(RedisConstant.USER_CONDITION + MySysUser.id(),
     *                 condition.getId(),
     *                 JSON.toJSONString(condition));
     */

}
